package com.azzcs.userservice.controller;

import com.azzcs.userservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: wzg
 * @Date: 2021/2/20 上午11:21
 */
@RefreshScope
@RestController
@RequestMapping("register")
public class RegisterController {

    @Autowired
    private UserService userService;

    @GetMapping("/{email}/{password}/{code}")
    public Integer register(@PathVariable("email") String email,
                            @PathVariable("password") String password,
                            @PathVariable("code") Integer code,
                            HttpServletResponse response){
        Integer register = userService.register(email, password, code);
        if(register == 0) {
            String token = userService.createToken(email);
            response.setHeader("token", token);
        }
        return register;
    }


}
